import os

def find_proc(pidname):
    "mac上面找到appiumserver的，result里面写法需要带空格"
    result ="ps -C "+pidname+" | grep -v CMD |awk '{ print $1 }').readlines()[0]"
    os.popen(result)
find_proc("pidname")  #appium的进程名 pidname<type:str>

def run_proc(name):
    "测试代码,pid随时在变 实验代码本身不会创造1个进程，但执行时会产生1个进程name，同时销毁"
    print("进程运行中, name=%s ,pid=%d " % (name, os.getpid()))
    pname ="tasklist |findstr "+name
    restore =os.system(pname)
    print(restore >>8)  #0代表成功，但实际是虚拟的。但python程序会认这段
#run_proc("chenziang.exe")

def run_procPopen(name):
    "测试popen效果的代码"
    print("进程运行中, name=%s ,pid=%d " % (name, os.getpid()))
    pname ="tasklist |findstr "+name
    restore =os.popen(pname)
    print(restore)
run_procPopen("py.exe") #<os._wrap_close object at 0x02174990>